package org.jeecg.service.service;

import org.jeecg.domain.Collect;
import org.jeecg.domain.Goods;
import org.jeecg.mapper.CollectMapper;
import org.jeecg.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class CollectServiceImpl implements CollectService {

    @Autowired
    private CollectMapper collectMapper;

    @Override
    public Boolean insertCollect(String username, String goodId) {
        UUID uuid = UUID.randomUUID();
        //生成一个16位的UUID
        String id = uuid.toString().replace("-","").substring(0,16);
        Date date = new Date();

        Collect collect = new Collect(id,username,goodId,date);
        Integer result = collectMapper.insertColect(collect);
        if (result > 0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean cancelCollect(String username, String goodId) {
        Integer result = collectMapper.cancelCollect(username, goodId);
        if (result > 0){
            return true;
        }
        return false;
    }

    @Override
    public List<Goods> getGoodsByUsername(String username) {
        List<Goods> goods = collectMapper.queryGoodsByUsername(username);

        return goods;
    }

    @Override
    public Boolean queryCollect(String username, String goodId) {
        Collect collect = collectMapper.queryCollect(username, goodId);
        if (collect != null){
            return true;
        }
        return false;
    }
}
